package com.sudu.service.impl;

import com.sudu.dao.UserDao;
import com.sudu.domain.User;
import com.sudu.domain.UserInfo;
import com.sudu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 登录/注册 用户的业务层接口的实现类
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao ;

    @Override
    public boolean saveUser(User user) {
        try {
            return userDao.saveUser(user) > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public User fineByUsername(String username) {
        return userDao.fineByUsername(username);
    }

    @Override
    public User fineByPhone(String phone) {
        return  userDao.fineByPhone(phone);
    }

    @Override
    public User fineByID(int id) {
        return  userDao.fineById(id);
    }

    @Override
    public String finePhoneByUid(int uid) {
        return userDao.finePhoneByUid(uid);
    }

    @Override
    public boolean updateCardCase(int id, String cardCase) {

        return userDao.updateCardCase(id, cardCase) > 0;
    }

    @Override
    public boolean updateUsername(int id, String username) {
        return userDao.updateUsername(id, username) > 0;
    }

    @Override
    public boolean updateHandUrl(int id, String handUrl) {
        return userDao.updateHandUrl(id, handUrl) > 0;
    }

    @Override
    public UserInfo getUserInfoById(int id) {
        return userDao.getUserInfoById(id);
    }

    @Override
    public boolean updateUserinfo(String username , String cardCase , String sex ,int id) {
        return userDao.updateUserinfo(username , cardCase , sex ,id) > 0;
    }

    @Override
    public boolean deleteUser(int id , String username , String handUrl) {

        return false;
    }


}
